package org.jeecg.modules.basic.report.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.basic.report.entity.*;

import org.jeecg.modules.basic.report.service.MaterialReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * TODO
 *
 *
 */
@Api(tags="物料统计")
@RestController
@RequestMapping("/report/lwgyMaterialReport")
@Slf4j
public class MaterialReportController extends JeecgController<LwgyMaterialReport, MaterialReportService> {

    @Autowired
    private MaterialReportService materialReportService;


    @PostMapping("/inUseReport")
    public Result<?>inUseReport(@RequestBody InReport inReport){
        List<InReport> reportList = materialReportService.inUseReport(inReport);
        List<Map<String,Integer>> inUseList = new ArrayList<>(5);
        Map<String,Integer>map1 = new LinkedHashMap<>(6);
        Map<String,Integer>map2 = new LinkedHashMap<>(6);
        Map<String,Integer>map3 = new LinkedHashMap<>(6);
        for (InReport report : reportList) {
            map1.put(report.getStudentCampus(),report.getPrice());//
            map2.put(report.getStudentCampus(),report.getCounts());
            map3.put(report.getStudentCampus(),report.getTotalPrice());//
        }
        inUseList.add(map1);
        inUseList.add(map2);
        inUseList.add(map3);
        return Result.OK(inUseList);
    }

    @PostMapping("/outUseReport")
    public Result<?>outUseReport(@RequestBody OutReport outReport){
        List<OutReport> reportList = materialReportService.outUseReport(outReport);
        List<Map<String,Integer>> inUseList = new ArrayList<>(5);
        Map<String,Integer>map1 = new LinkedHashMap<>(6);
        Map<String,Integer>map2 = new LinkedHashMap<>(6);
        for (OutReport report : reportList) {
            map1.put(report.getStudentCampus(),report.getPrice());//
            map2.put(report.getStudentCampus(),report.getCounts());
        }
        inUseList.add(map1);
        inUseList.add(map2);
        return Result.OK(inUseList);
    }
    @PostMapping("/useReport")
    public Result<?>useReport(@RequestBody UseReport useReport){
        List<UseReport> reportList = materialReportService.useReport(useReport);
        List<Map<String,Integer>> inUseList = new ArrayList<>(5);
        Map<String,Integer>map1 = new LinkedHashMap<>(6);
        Map<String,Integer>map2 = new LinkedHashMap<>(6);
        for (UseReport report : reportList) {
            map1.put(report.getCampusId(),report.getPrice());//
            map2.put(report.getCampusId(),report.getCounts());
        }
        inUseList.add(map1);
        inUseList.add(map2);
        return Result.OK(inUseList);
    }
    @PostMapping("/materialsReport")
    public Result<?>materialsReport(@RequestBody MaterialsReport materialsReport){
        List<MaterialsReport> reportList = materialReportService.materialsReport(materialsReport);
        System.out.println("7777777:"+reportList);
        List<Map<String,Integer>> inUseList = new ArrayList<>(5);
        Map<String,Integer>map1 = new LinkedHashMap<>(6);
        Map<String,Integer>map2 = new LinkedHashMap<>(6);
        Map<String,Integer>map3 = new LinkedHashMap<>(6);
        for (MaterialsReport report : reportList) {
            map1.put(report.getStudentCampus(),report.getBuyCount());
            map2.put(report.getStudentCampus(),report.getInCount());//
            map3.put(report.getStudentCampus(),report.getOutCount());//
        }
        inUseList.add(map1);
        inUseList.add(map2);
        inUseList.add(map3);
        return Result.OK(inUseList);
    }



    @PostMapping("/inUseReportList")
    public Result<?> inUseReportList(@RequestBody InReport inReport){
        List<InReport> reportList = materialReportService.inUseReport(inReport);
        IPage<InReport> reportIPage = new Page<>(0,100);
        reportIPage.setRecords(reportList);
        return Result.OK(reportIPage);
    }
    @PostMapping("/outUseReportList")
    public Result<?> outUseReportList(@RequestBody OutReport outReport){
        List<OutReport> reportList = materialReportService.outUseReport(outReport);
        IPage<OutReport>reportIPage = new Page<>(0,100);
        reportIPage.setRecords(reportList);
        return Result.OK(reportIPage);
    }

    @PostMapping("/useReportList")
    public Result<?> useReportList(@RequestBody UseReport useReport){
        List<UseReport> reportList = materialReportService.useReport(useReport);
        IPage<UseReport>reportIPage = new Page<>(0,100);
        reportIPage.setRecords(reportList);
        return Result.OK(reportIPage);
    }

    @PostMapping("/materialsReportList")
    public Result<?> materialsReportList(@RequestBody MaterialsReport materialsReport){
        List<MaterialsReport> reportList = materialReportService.materialsReport(materialsReport);
        System.out.println("7777777:"+reportList);
        IPage<MaterialsReport>reportIPage = new Page<>(0,100);
        reportIPage.setRecords(reportList);
        return Result.OK(reportIPage);
    }



}
